    /*  
    championBuilder - Champions Online character planner.
    Copyright (C) 2009 Moritz Hartmeier
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You can find the GNU General Public License in the data folder.
    */


package ch.zarzu.champions.builder.gui;

import java.awt.*;
import java.awt.event.*;
import java.util.LinkedList;

import javax.swing.*;

import ch.zarzu.util.*;

public class AdvantageBubbles extends JLayeredPane {
    SpringLayout layout;
    LinkedList<JButton> bubbles;
    int active;
    private String app_path;
    
    public AdvantageBubbles(MouseListener listener, int button_width) {
        layout = new SpringLayout();
        setLayout(layout);
        
        app_path = AppPath.get();
        
        active = 0;
        int offset = 0;
        
        ImageIcon icon = new ImageIcon(app_path + "images/advantages/bubble_a.png");
        bubbles = new LinkedList<JButton>();
        JButton button;
        for(int i = 0; i < 5; i++) {
            button= new JButton(icon);
            button.setBorder(null);
            button.setFocusable(false);
            button.setContentAreaFilled(false);
            button.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
            button.addMouseListener(listener);
            add(button);
            bubbles.add(button);
            
            offset += icon.getIconWidth() - 3;
        }
        
        layout.putConstraint(SpringLayout.WEST, bubbles.get(0), (button_width - (offset))/2, SpringLayout.WEST, this);
        layout.putConstraint(SpringLayout.WEST, bubbles.get(1), -3, SpringLayout.EAST, bubbles.get(0));
        layout.putConstraint(SpringLayout.WEST, bubbles.get(2), -3, SpringLayout.EAST, bubbles.get(1));
        layout.putConstraint(SpringLayout.WEST, bubbles.get(3), -3, SpringLayout.EAST, bubbles.get(2));
        layout.putConstraint(SpringLayout.WEST, bubbles.get(4), -3, SpringLayout.EAST, bubbles.get(3));
        layout.putConstraint(SpringLayout.EAST, this, 0, SpringLayout.EAST, bubbles.get(4));
        layout.putConstraint(SpringLayout.SOUTH, this, 0, SpringLayout.SOUTH, bubbles.get(4));
    }
    
    public void setActive(int i) {
        active = i;
        for(int j = 0; j < 5; j++) {
            if(j < i)
                bubbles.get(j).setIcon(new ImageIcon(app_path + "images/advantages/bubble_b.png"));
            else
                bubbles.get(j).setIcon(new ImageIcon(app_path + "images/advantages/bubble_a.png"));
        }
    }
}
